package expression;

import java.util.HashMap;
import java.util.LinkedList;

public class FnBoolOR extends Fn implements FnBool {

	public FnBoolOR() {}

	@Override
	protected boolean isAcceptableChild(Fn fn) {
		return (fn instanceof FnBool);
	}

	@Override
	protected boolean isAcceptableParam(Object o) {
		return (o instanceof Boolean);
	}
	
	@Override
	public int getNParam() {
		return 2;
	}

	@Override
	protected int precedence() {
		return 1;
	}

	@Override
	protected Object value(LinkedList<Object> param) {
		for (Object operand : param)
			if (operand instanceof Boolean)
				if ((boolean) operand)
					return true;
		return false;
	}

	@Override
	public String symbol() {
		return "|";
	}

	@Override
	protected String[] notation() {
		return new String[]
		{ "", " | ", "" };
	}

	public static void main(String[] args) throws ExpressionException {
		FnBoolOR or = new FnBoolOR();
		or.addParam(new FnVariable("X"));
		or.addParam(new FnVariable("Y"));
		or.addParam(new FnVariable("Z"));
		System.out.println(or);

		HashMap<String, Object> varSub = new HashMap<>();
		varSub.put("X", false);
		varSub.put("Y", false);
		varSub.put("Z", true);
		System.out.println(or.evaluate(varSub));
	}

}
